package screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.RunnableAction;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.Action;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.me.mygdxgame.Gamedoan;

public class SplashScreen implements Screen {

	Gamedoan myGame;
	SpriteBatch spriteBatch;
	Texture splashTexture;
	Stage stage;
	public SplashScreen(Gamedoan game){
		myGame=game;
		Action action;
		stage = new Stage();
	}
	@Override
	public void render(float delta) {
		// TODO Auto-generated method stub
		 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		 stage.act(delta);
		 stage.draw();
       /*  spriteBatch.begin();
         spriteBatch.draw(splashTexture, 0, 0);
         spriteBatch.end();*/
         
         if(Gdx.input.justTouched())
                 myGame.setNextScreen();
         this.dispose();
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub
		
		
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		spriteBatch = new SpriteBatch();
		splashTexture = new Texture (Gdx.files.internal("background/splashScreen.png"));
		TextureRegion splashRegion = new TextureRegion (splashTexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	    Image splashImage = new Image(splashRegion);
	    splashImage.setWidth(Gdx.graphics.getWidth());
	    splashImage.setHeight(Gdx.graphics.getHeight());
	    splashImage.getColor().a = 0f;
	    Action completeAction = new Action(){
	        public boolean act( float delta ) {
	            // Do your stuff
	            myGame.setNextScreen();
				return true;
	        }
	    };
	    splashImage.addAction(Actions.sequence(Actions.fadeIn(0.75f),Actions.delay(1f),Actions.fadeOut(0.75f),completeAction));
	    
	    stage.addActor(splashImage);
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}
	
}
